package comm

import (
	"go.uber.org/zap"
	"go.uber.org/zap/zapcore"
)

var Log *zap.SugaredLogger

func init() {
	logger, _ := zap.NewDevelopment()
	Log = logger.Sugar()
	Log.Info("zap日志初始化完成")
}

func NewLogger(fields ...zapcore.Field) *zap.SugaredLogger {
	return cloneLogger(Log, fields...)
}

func cloneLogger(l *zap.SugaredLogger, fields ...zapcore.Field) *zap.SugaredLogger {
	// copy
	var logger = *l
	var args = make([]interface{}, len(fields))
	for i, f := range fields {
		args[i] = f
	}
	return logger.With(args...)
}
